//
//  LFTMController.m
//  ServiceBaZhou
//
//  Created by 刘江涛 on 2017/8/24.
//  Copyright © 2017年 weierda. All rights reserved.
//

#import "LFTMController.h"

#import "ProductCell.h"

#import "TMModel.h"

#import "UIImageView+WebCache.h"

@interface LFTMController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) NSMutableArray *dataArray;

@property (nonatomic,strong) UITableView *tableView;

@end

@implementation LFTMController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTableView];
    
    [self loadData];
    
    [self createNavigation:@"商标信息"];
}

- (void)loadData{
    NSMutableDictionary *para = [NSMutableDictionary dictionaryWithCapacity:0];
    [para setObject:Token forKey:@"key"];
    [para setObject:_companyName forKey:@"keyword"];
    [para setObject:@"50" forKey:@"pageSize"];
    
    [CFHttpTools getRequest:@"tm/Search" params:para success:^(id responseObj) {
        //
        CFLog(@"%@",responseObj);
        
        if(![responseObj[@"Result"] isKindOfClass:[NSArray class]]){
            if([CFToolUtil isBlankString:responseObj[@"Result"]]){
                UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 64, Width - 100 , Width - 100)];
                imageView.image = [UIImage imageNamed:@"nodata"];
                [self.tableView addSubview:imageView];
                
                UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, Width - 20, Width, 20)];
                label.text = @"暂无数据";
                label.textColor = [UIColor grayColor];
                label.textAlignment = NSTextAlignmentCenter;
                [self.tableView addSubview:label];
            }
        }else{
            
            NSArray *LFTMArray = responseObj[@"Result"];
            
            JSONModelArray *modelArray = [[JSONModelArray alloc]initWithArray:LFTMArray modelClass:[TMModel class]];
            
            self.dataArray = [NSMutableArray array];
            
            [self.dataArray addObjectsFromArray:(NSArray *)modelArray];
            
            [_tableView reloadData];
            
        }
    } failure:^(NSError *error) {
        //
    }];
}

- (void)createTableView{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, Width, Height - 64) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = NO;
    
    [_tableView registerNib:[UINib nibWithNibName:@"ProductCell" bundle:nil] forCellReuseIdentifier:@"ProductCell"];
    [self.view addSubview:_tableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 115;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ProductCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProductCell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    TMModel *model = _dataArray[indexPath.row];
    
    [cell.productImageView sd_setImageWithURL:[NSURL URLWithString:model.ImageUrl] placeholderImage:[UIImage imageNamed:@"LFdefault"]];
    
    cell.nameLabel.text = model.Name;
    
    if(![CFToolUtil isBlankString:model.FlowStatusDesc]){
        [cell.decripLabel setAlpha:1.0];
    }
    cell.decripLabel.text = [NSString stringWithFormat:@"  %@  ",model.FlowStatusDesc];
    
    cell.dominLabel.text = [NSString stringWithFormat:@"注册号：%@",model.RegNo];
    cell.companyLabel.text = [NSString stringWithFormat:@"申请时间：%@",model.AppDate];
    cell.tagsLabel.text = [NSString stringWithFormat:@"申请人：%@",model.ApplicantCn];
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
